calendarswikiaorg-20200214-history
Doomsday algorithm
The Doomsday rule or Doomsday algorithm is a way of calculating the day of the week of a given date. It provides a perpetual calendar; since the Gregorian calendar moves in cycles of 400 years. This algorithm for mental calculation was devised by John Horton Conway after drawing inspiration from Lewis Carroll's work on a perpetual calendar algorithm. It takes advantage of the fact that each year has a certain day of the week (the doomsday) upon which certain easy-to-remember dates fall; for example, 4/4, 6/6, 8/8, 10/10, 12/12, and the last day of February all occur on the same day of the week in any given year. Applying the Doomsday algorithm involves three steps: #Determine the "anchor day" for the century. #Use the anchor day for the century to calculate the doomsday for the year. #Choose the closest date out of the ones that always fall on the doomsday (e.g. 4/4, 6/6, 8/8), and count the number of days (mod 7) between that date and the date in question to arrive at the day of the week. This technique applies to both the Gregorian calendar A.D. and the Julian calendar, although their doomsdays will usually be different days of the week. Since this algorithm involves treating days of the week like numbers modulo 7, John Conway suggests thinking of the days of the week as "Noneday" or "Sansday" (for Sunday), "Oneday", "Twosday", "Treblesday", "Foursday", "Fiveday", and "Six-a-day". The algorithm is simple enough for anyone with basic arithmetic ability to do the calculations mentally. Conway can usually give the correct answer in under two seconds. To improve his speed, he practices his calendrical calculations on his computer, which is programmed to quiz him with random dates every time he logs on. Doomsdays for some contemporary years Doomsday for the current year in the Gregorian calendar (2015) is Saturday. For some other contemporary years: Notes: Fill in the table horizontally, skipping one column for each leap year. This table cycles every 28 years, except in the Gregorian calendar on years multiple of 100 (like 1900 which is not a leap year) that are not multiple of 400 (like 2000 which is still a leap year). The full cycle is 28 years (1,461 weeks) in the Julian calendar, 400 years (20,871 weeks) in the Gregorian calendar. Memorable dates that always land on Doomsday One can easily find the day of the week of a given calendar date by using a nearby Doomsday as a reference point. To help with this, the following is a list of easy-to-remember dates for each month that always land on the Doomsday. As mentioned above, the last day of February always falls on the doomsday, as do the double dates 4/4, 6/6, 8/8, 10/10, and 12/12. Four of the odd month dates (May 9, September 5, July 11, and November 7) can be remembered with the mnemonic "I work from 9 to 5 at the 7-11." For March, one can remember the pseudo-date "March 0", which refers to the day before March 1, i.e. the last day of February; one can alternately remember the date a week later, March 7, or March 21 which is often the first day of spring in the northern hemisphere and the first day of fall in the southern hemisphere. For January, January 11 is a Doomsday during leap years, while January 10 is a Doomsday during common years; January 3 is a doomsday during common years and January 4 a Doomsday during leap years, which can be remembered as "the 3rd during 3''' years in 4, and the 4th in the '4'th". Since the Doomsday for a particular year is directly related to weekdays of dates in the period from March through February of the next year, common years and leap years have to be distinguished for January and February of the same year. Examples Suppose you want to know which day of the week Christmas Day of 2006 was. In the year 2006, Doomsday was Tuesday. Since December 12 is a Doomsday, December 25, being thirteen days afterwards (two weeks less a day), fell on a Monday. It's useful to note that Christmas Day is always the day before Doomsday ("One off Doomsday"). In addition, July 4 is always on a Doomsday, and so is Halloween. Suppose that you want to find the day of week that the September 11, 2001 attacks on the World Trade Center occurred. The century anchor was Tuesday, and Doomsday for 2001 is one day beyond, which is Wednesday. September 5 was a Doomsday, and September 11, six days later, fell on a Tuesday. Finding a year's Doomsday We first take the anchor day for the century. For the purposes of the Doomsday rule, a century starts with '00 and ends with '99. The following table shows the anchor day of centuries 1800–1899, 1900–1999, 2000–2099 and 2100–2199. Next, we find the year's Doomsday. To accomplish that according to Conway: #Divide the year's last two digits (call this y'') by 12 and let ''a be the floor of the quotient. #Let b'' be the remainder of the same quotient. #Divide that remainder by 4 and let ''c be the floor of the quotient. #Let d'' be the sum of the three numbers (''d = a'' + ''b + c''). (It is again possible here to divide by seven and take the remainder. This number is equivalent, as it must be, to the sum of the last two digits of the year taken collectively plus the floor of those collective digits divided by four.) #Count forward the specified number of days (''d or the remainder of d''/7) from the anchor day to get the year's Doomsday. : For the twentieth-century year 1966, for example: : As described in bullet 4, above, this is equivalent to: : So Doomsday in 19'66 fell on Monday. Similarly, Doomsday in 20'05' is on a Monday: : Why it works The doomsday calculation is effectively calculating the number of days between any given date in the base year and the same date in the current year, then taking the remainder modulo 7. When both dates come after the leap day (if any), the difference is just 365y plus y/4 (rounded down). But 365 equals 52*7+1, so after taking the remainder we get just: (y+\left\lfloor \frac{y}{4}\right\rfloor) This gives a simpler formula if one is comfortable dividing large values of y by both 4 and 7. For example, we can compute (66+\left\lfloor \frac{66}{4}\right\rfloor)\mod 7=(66+16)\mod 7=82\mod 7=5 , which gives the same answer as in the example above. This gives a simpler formula if one is comfortable dividing large values of y by both 4 and 7. For example, we can compute , which gaves the same answer as in the example above. Where 12 comes in is that the pattern of (y+\left\lfloor \frac{y}{4}\right\rfloor) almost repeats every 12 years. After 12 years, we get (12 + 12/4) mod 7 = 15 mod 7 = 1. If we replace y by y mod 12, we are throwing this extra day away; but adding back in \left\lfloor \frac{y}{12}\right\rfloor compensates for this error, giving the final formula. The Odd+11 method A simpler method for finding the year's doomsday was discovered in 2010. Called the Odd+11 method, it has been proved equivalent to computing : It is well suited to mental calculation, because it requires no division by 4 (or 12), and the procedure is easy to remember because of its repeated use of the "odd+11" rule. The procedure accumulates a running total T'' as follows: #Let ''T be the year's last two digits. #If T'' is odd, add 11. #Let ''T = T''/2. #If ''T is odd, add 11. #Let T'' = 7 − (''T mod 7). #Count forward T'' days from the anchor day to get the year's Doomsday. Applying this method to the year 1966, for example, the steps as outlined would be: #''T = 66 #''T'' = 66 (Do nothing since T'' is even.) #''T = 66/2 = 33 #''T'' = 33+11 = 44 (Add 11 because T is odd.) #''T'' = 7 − (44 mod 7) = 7 − 2 = 5 #Doomsday 1966 = 5 + Wednesday = Monday Category:Algorithms